package com.juzipi.thread.test;

/**
 * @Author juzipi
 * @Date 2021/6/15 15:13
 * @Info
 */
public class ThreadMany implements Runnable {

    private static int number = 100;

    @Override
    public void run() {
        while (true){
            if (number <=0){
                break;
            }
            System.out.println(Thread.currentThread().getName()+"拿到了第"+number--+"张票");
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    //多个线程同时操作同一对象
    public static void main(String[] args) {
        ThreadMany threadMany = new ThreadMany();
        new Thread(threadMany,"线程一").start();
        new Thread(threadMany,"线程二").start();
        new Thread(threadMany,"线程三").start();
        new Thread(threadMany,"线程四").start();

    }

}
